import com.beans.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class App {
    public static void main(String[] args) {

        //1.先得到spring上下文对象
        ApplicationContext context = new ClassPathXmlApplicationContext("spring2-config.xml");
        BeanScope1 beanScope1= context.getBean(BeanScope1.class);
        User user1 = beanScope1.getUser3();
        System.out.println("BeanScope1" + user1);

        BeanScope2 beanScope2 = context.getBean(BeanScope2.class);
        User user2 = beanScope2.getUser3();
        System.out.println("BeanScope2" + user2);


//        UserController4 userController4 = context.getBean(UserController4.class);
//        userController4.sayHi();

//        UserController2 userController2 = context.getBean(UserController2.class);
//        userController2.sayHi();

//        UserController userController = context.getBean(UserController.class);
//        userController.sayHi();

//        //User user = context.getBean("user1",User.class);
//        User user = context.getBean("userinfo",User.class);
//        System.out.println(user);

//        //2.根据上下文对象找到bean方法
//        UserController controller = context.getBean("userController", UserController.class);
//
//        //3.使用bean
//        controller.sayHi();

//        UserService userService = context.getBean(UserService.class);
//        userService.sayHi();

//        UserRepository userRepository = context.getBean(UserRepository.class);
//        userRepository.sayHi();

//        UserConfig userConfig = context.getBean(UserConfig.class);
//        userConfig.sayHi();

//        UserComponent userComponent = context.getBean(UserComponent.class);
//        userComponent.sayHi();


    }
}
